// i.d(t, { S: () => n })

import funcUtil from "./func.util"

export default {
  sessionObjectExtract: (e, t) => i => t(i ? i[e] : null),
  sessionObjectMap: (e, t, i) => n => i(n ? { [t]: n[e] } : null),
  sessionCollectionMap: (e, t) => {
    return i => {
      if (i) {
        const n = {},
          s = i[e]
        if (!(s && s instanceof Array)) return t(null)
        for (const e of s) {
          if (!e.sid) {
            let t
            do {
              t = funcUtil.randomStr(11)
            } while (s.find(e => e.sid === t))
            e.sid = t
          }
          n[e.sid] = e
        }
        return t(n)
      }
      return t(null)
    }
  }
}
